home *** CD-ROM | disk | FTP | other *** search
/ Champak 26 (Anniversary Edition) / Volume 26 [Anniversary Edition] - JOGO DISK .iso / DEPOSITO / REmovido / Esportes / 814.swf / scripts / DataProviderSymbol.as < prev    next >
Text File  |  2006-06-13  |  3KB  |  101 lines

  1. _global.DataProviderClass = function()
  2. {
  3.    this.init();
  4. };
  5. DataProviderClass.prototype.init = function()
  6. {
  7.    this.items = new Array();
  8.    this.uniqueID = 0;
  9.    this.views = new Array();
  10. };
  11. DataProviderClass.prototype.addView = function(viewRef)
  12. {
  13.    this.views.push(viewRef);
  14.    var eventObj = {event:"updateAll"};
  15.    viewRef.modelChanged(eventObj);
  16. };
  17. DataProviderClass.prototype.addItemAt = function(index, value)
  18. {
  19.    if(index < this.getLength())
  20.    {
  21.       this.items.splice(index,0,"tmp");
  22.    }
  23.    this.items[index] = new Object();
  24.    if(typeof value == "object")
  25.    {
  26.       this.items[index] = value;
  27.    }
  28.    else
  29.    {
  30.       this.items[index].label = value;
  31.    }
  32.    this.items[index].__ID__ = this.uniqueID++;
  33.    var eventObj = {event:"addRows",firstRow:index,lastRow:index};
  34.    this.updateViews(eventObj);
  35. };
  36. DataProviderClass.prototype.addItem = function(value)
  37. {
  38.    this.addItemAt(this.getLength(),value);
  39. };
  40. DataProviderClass.prototype.removeItemAt = function(index)
  41. {
  42.    var tmpItm = this.items[index];
  43.    this.items.splice(index,1);
  44.    var eventObj = {event:"deleteRows",firstRow:index,lastRow:index};
  45.    this.updateViews(eventObj);
  46.    return tmpItm;
  47. };
  48. DataProviderClass.prototype.removeAll = function()
  49. {
  50.    this.items = new Array();
  51.    this.updateViews({event:"deleteRows",firstRow:0,lastRow:this.getLength() - 1});
  52. };
  53. DataProviderClass.prototype.replaceItemAt = function(index, itemObj)
  54. {
  55.    if(index < 0 || index >= this.getLength())
  56.    {
  57.       return undefined;
  58.    }
  59.    var tmpID = this.getItemID(index);
  60.    if(typeof itemObj == "object")
  61.    {
  62.       this.items[index] = itemObj;
  63.    }
  64.    else
  65.    {
  66.       this.items[index].label = itemObj;
  67.    }
  68.    this.items[index].__ID__ = tmpID;
  69.    this.updateViews({event:"updateRows",firstRow:index,lastRow:index});
  70. };
  71. DataProviderClass.prototype.getLength = function()
  72. {
  73.    return this.items.length;
  74. };
  75. DataProviderClass.prototype.getItemAt = function(index)
  76. {
  77.    return this.items[index];
  78. };
  79. DataProviderClass.prototype.getItemID = function(index)
  80. {
  81.    return this.items[index].__ID__;
  82. };
  83. DataProviderClass.prototype.sortItemsBy = function(fieldName, order)
  84. {
  85.    this.items.sortOn(fieldName);
  86.    if(order == "DESC")
  87.    {
  88.       this.items.reverse();
  89.    }
  90.    this.updateViews({event:"sort"});
  91. };
  92. DataProviderClass.prototype.updateViews = function(eventObj)
  93. {
  94.    var i = 0;
  95.    while(i < this.views.length)
  96.    {
  97.       this.views[i].modelChanged(eventObj);
  98.       i++;
  99.    }
  100. };
  101.